<?php

namespace app\common\model;

use think\Model;

class RechargePackage extends Model
{
    // 表名
    protected $name = 'recharge_package';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'type_text',
        'pay_type_text',
        'status_text'
    ];
    

    
    public function getTypeList()
    {
        return self::$_type;
    }     

    public function getPayTypeList()
    {
        return self::$_pay_type;
    }     

    public function getStatusList()
    {
        return self::$_status;
    }     


    public function getTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['type'];
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['pay_type'];
        $list = $this->getPayTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
	
	const TYPE_1 = 1;
	const TYPE_2 = 2;
	const TYPE_3 = 3;
	const TYPE_4 = 4;
	const TYPE_5 = 5;
	const TYPE_7 = 7;
	
	const STATUS_Y =  1;
	const STATUS_N = 0;
	
	/**
	 * @var array 充值类型
	 */
	public static $_type = [
		self::TYPE_3 => '话费',
		self::TYPE_1 => '余额',
		self::TYPE_2 => '积分',
		self::TYPE_4 => '优惠券',
	];
	
	/**
	 * @var array 支付方式
	 */
	public static $_pay_type = [
		self::TYPE_1 => '余额',
		self::TYPE_2 => '积分',
		self::TYPE_3 => '话费',
		self::TYPE_4 => '优惠券',
		self::TYPE_5 => '在线支付'
	];
	
	/**
	 * @var array 充值及付款方式对应的user表字段
	 */
	public static $_fields = [
		self::TYPE_4 => 'voucher_balance',
		self::TYPE_3 => 'phone_balance',
		self::TYPE_2 => 'integral',
		self::TYPE_1 => 'balance',
//		self::TYPE_6 => 'money1',
	];
	
	/**
	 * @var array 套餐状态
	 */
	public static $_status = [
		self::STATUS_Y => '正常',
		self::STATUS_N => '禁用'
	];


}
